﻿@using LanDBom.Models
@{
    ViewBag.Title = "Pricing";
}
@section styles{
    <style>
        
        th{
            width:150px;
            text-align:center;
        }
    </style>
}

<from>
    <fieldset class="boun">
        <legend></legend>
        <div class="row bian">
            <label class="col-sm-3 breadcrumb-item active">步骤五：采购核价</label>
            <ul id="lisul" class="row col-sm-5">
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu">5</li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>
            </ul>
        </div>
    </fieldset>
</from>
<from class="from-horizontal row">
    <div style="width:1000px;">
        <fieldset class="boun row">
            <legend id="HJ_SQDH">@(Session["CG_INFSQD"])</legend>
            <div style="width:1000px;display:none;position:fixed;background-color:dimgrey;z-index:100" id="HJ_SF">
                <div>
                    <div>
                        <ul>
                            <li>纸板</li>
                        </ul>
                    </div>
                    <div id="CBJSTJ" style="color:white">提交</div>
                    <div id="HJ_fh" style="color:white">返回</div>
                    <div id="JS_WLXX" style="background-color:black;color:white;text-align:center;font-size:20px"></div>
                    <div style="overflow:scroll">
                        <div style="display:none" id="YCFZ"></div>
                        <div style="display:none" id="YCSH"></div>
                        <table width="2000px">
                            <thead>
                                <tr class="JS_thead_1">
                                    <th rowspan="2">楞型</th>
                                    <th colspan="2">面纸</th>
                                    <th colspan="3">瓦楞</th>
                                    <th colspan="2">底纸/中纸</th>
                                    <th colspan="3">瓦楞</th>
                                    <th colspan="2">底纸</th>
                                    <th rowspan="2">加工费</th>
                                    <th rowspan="2">纸板成本价</th>
                                    <th rowspan="2">纸板平方价</th>
                                </tr>
                                <tr>
                                    <th>面纸类型</th>
                                    <th>面纸克重</th>
                                    <th>楞别</th>
                                    <th>瓦楞系数</th>
                                    <th>瓦楞克重</th>
                                    <th>底纸/中纸类型</th>
                                    <th>底纸/中纸克重</th>
                                    <th>楞别</th>
                                    <th>瓦楞系数</th>
                                    <th>瓦楞克重</th>
                                    <th>底纸类型</th>
                                    <th>底纸克重</th>
                                </tr>
                            </thead>
                            <tbody id="HJTable">
                                <tr>
                                    <th id="JS_ZLB">
                                    </th>
                                    <th>
                                        <select class="form-control JS_HZLX" id="JS_HZLX">
                                            <option value="-99">--请选择--</option>
                                            @foreach (var item in ViewBag.ListZBxx as List<parice>)
                                            {
                                                @*if (@item.PA_name != null)
                                                {
                                                    <option value="@item.PA_name" id="CL_ID">@item.PA_name</option>
                                                }*@

                                            }
                                        </select>
                                    </th>
                                    <th class="JS_ZDJ" id="JS_ZDJ">
                                        <select name="CL_name" class="form-control">
                                            <option value="-99">--请选择--</option>
                                        </select>
                                        <div id="Z1" style="display:none">
                                        </div>

                                    </th>
                                    <th>
                                        <select class="form-control JS_LB" id="JS_LB1">
                                            <option value="">--请选择--</option>
                                            @foreach (var item in ViewBag.ListZBxx as List<parice>)
                                            {
                                                @*if (@item.PA_Xishu != null)
                                                {
                                                    <option value="@item.PA_LengBie" id="CL_ID">@item.PA_LengBie</option>
                                                }*@

                                            }
                                        </select>
                                    </th>
                                    <th class="JS_WLXS">
                                        <select name="CL_name" class="form-control">
                                            <option value="-99">--请选择--</option>
                                        </select>
                                    </th>
                                    <th>
                                        <div>
                                            <input type="text" class="JS_WLKZ" />
                                        </div>
                                        <div id="Z2" style="display:none">
                                        </div>

                                    </th>
                                    <th>
                                        <select class="form-control JS_HZLX" id="JS_HZLX">
                                            <option value="-99">--请选择--</option>
                                            @foreach (var item in ViewBag.ListZBxx as List<parice>)
                                            {
                                                @*if (@item.PA_name != null)
                                                {
                                                    <option value="@item.PA_name" id="CL_ID">@item.PA_name</option>
                                                }*@
                                            }
                                        </select>
                                    </th>
                                    <th class="JS_ZDJ">
                                        <select name="CL_name" class="form-control">
                                            <option value="-99">--请选择--</option>
                                        </select>
                                        <div id="Z3" style="display:none">
                                        </div>
                                    </th>
                                    <th>
                                        <select class="form-control JS_LB" id="JS_LB2">
                                            <option value="">--请选择--</option>
                                            @foreach (var item in ViewBag.ListZBxx as List<parice>)
                                            {
                                                @*if (@item.PA_Xishu != null)
                                                {
                                                    <option value="@item.PA_LengBie" id="CL_ID">@item.PA_LengBie</option>
                                                }*@
                                            }
                                        </select>
                                    </th>
                                    <th class="JS_WLXS">
                                        <select name="CL_name" class="form-control">
                                            <option value="-99">--请选择--</option>
                                        </select>
                                    </th>
                                    <th>
                                        <div>
                                            <input type="text" class="JS_WLKZ" />
                                        </div>
                                        <div id="Z4" style="display:none">
                                        </div>
                                    </th>
                                    <th>
                                        <select class="form-control JS_HZLX" id="JS_HZLX">
                                            <option value="-99">--请选择--</option>
                                            @foreach (var item in ViewBag.ListZBxx as List<parice>)
                                            {
                                                @*if (@item.PA_name != null)
                                                {
                                                    <option value="@item.PA_name" id="CL_ID">@item.PA_name</option>
                                                }*@
                                            }
                                        </select>
                                    </th>
                                    <th id="sunhao" class="JS_ZDJ">
                                        <select name="CL_name" class="form-control">
                                            <option value="-99">--请选择--</option>
                                        </select>
                                        <div id="Z5" style="display:none">
                                        </div>
                                    </th>
                                    <th id="JGF">
                                    </th>
                                    <th id="CHJG">
                                    </th>
                                    <th id="PFJG">
                                    </th>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div id="HJ_BigBox" style="width:100%">

            </div>
            <div id="HJ_TJJG">
                提交价格
            </div>
            <div id="HJ_WCHJ">
                完成核价
            </div>
            <div id="HJ_FH">
                返回
            </div>
        </fieldset>
    </div>
</from>

@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>

    <script>
        $(function () {
            $("#Z1").text(0)
            $("#Z2").text(0)
            $("#Z3").text(0)
            $("#Z4").text(0)
            $("#Z5").text(0)
            //加载申请单BOM信息
            var CG_INFSQD = $("#HJ_SQDH").text()
            ajax_BOM()
            function ajax_BOM() {
                $.ajax({
                    url: '/Procure/Pricing',
                    type: 'GET',
                    data: { "APP_bian": CG_INFSQD, "state": 1 },
                    success: function (data) {
                        createTR(data);
                    },
                    error: function () {
                        alert('Request Error')
                    }
                })
            }
            
            //打印BOM行
            function createTR(data) {
                $('#HJ_BigBox div').remove();
                $.each(data, function (i, item) {
                    //if (item.Nd_wuLiao == "kong") {
                        var $tr = $(`
                                <div>
                                    <div id="HJ_ZKXX">展开</div>
                                    <div class="row HJ_Box1" id="HJ_Box1">
                                        <div class="col-4" style="display:none">
                                            <div class="col-lg-5">BOM编号</div>
                                            <div class="col-lg-5">${item.BOM2_id}</div>
                                        </div>
                                        <div class="col-4">
                                            <div class="col-lg-5">物料信息</div>
                                            <div class="col-lg-5 wlxx">${item.BOM2_wuLiu}</div>
                                        </div>
                                        <div class="col-4">
                                            <div class="col-lg-5">料号</div>
                                            <div class="col-lg-5">${item.BOM2_liao}</div>
                                        </div>
                                        <div class="col-4">
                                            <div class="col-lg-5">层级</div>
                                            <div class="col-lg-5">${item.BOM2_chen}</div>
                                        </div>
                                        <div class="col-4">
                                            <div class="col-lg-5" id="HJ_JSCB">理论成本</div>
                                            <div class="col-lg-5" id="HJ_LLCB"></div>
                                        </div>
                                    </div>
                                    <div id="HJ_CGLB" style="display:none">
                                        <table class="table table-sm gun" style="background-color: #FFFFFF">
                                            <thead class="thead-light">
                                                <tr>
                                                    <th scope="col"><input type="checkbox" disabled="disabled" /></th>
                                                    <th scope="col"style="display:none">采购编号</th>
                                                    <th scope="col">供应商</th>
                                                    <th scope="col">供应商回价</th>
                                                    <th scope="col">物料名称</th>
                                                    <th scope="col">料号</th>
                                                </tr>
                                            </thead>
                                            <tbody data-spy="scroll">
        
                                            </tbody>
                                        </table>
 
                                    </div
                                    <hr>
                                </div>
        
                                `);
                        $('#HJ_BigBox').append($tr);
                    //}
                    
                })
            }
            //提交选中的供应商回价
            $(document).on("click", "#HJ_TJJG", function (a) {
                var Bomid = $(a.target).parent().prev().children().first().children().last().text()
                var BZJG = []
                var BZJG_CD = $(':radio:checked').parent().parent().length;
                alert(BZJG_CD)
                if (BZJG_CD < 0) {
                    alert("请选择一个供应商回价")
                }
                else {
                    $(':radio:checked').parent().parent().each(function (i, item) {

                        BZJG.push({
                            Nd_Gong: $("th[id='BZ_gys']", item).text(),
                            Nd_wuLiao: $("th[id='BZ_wu']", item).text(),
                            Nd_jiage: $("th[id='BZ_hj']", item).text(),
                            Nd_danwei:"平方米/元"
                        })
                        console.log("共" + BZJG.length + "数据");
                        console.log(BZJG);
                    })
                    $.ajax({
                        url: "/Procure/AddNdardo",
                        type: 'POST',
                        data: JSON.stringify(BZJG),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text) {
                            alert(text)
                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }
                    })

                }
            })
            //点击呼出纸板成本核算页面
            $(document).on("click", "#HJ_JSCB", function (x) {
                var wlxx = $(x.target).parent().prev().prev().prev().children().last().text()
                $("#HJ_SF").css({ "display": "block" });
                $("#JS_WLXX").text(wlxx)
                //点击第一个纸板类型切换损耗
                var SH = null //设置变量接受损耗
                var jgf = 0;//设置变量接受加工费
                $(document).on("change", "#JS_ZDJ", function (e) {
                    var MK = $(e.target).val();
                    var ML = $(e.target).parent().prev().children().first().val();
                    $.ajax({
                        url: "/Procure/Pricing",
                        type: 'GET',
                        data: { "MK": MK, "ML": ML, "state": 5 },
                        success: function (data) {
                            JSSH(data)
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    function JSSH(date) {
                        $.each(date, function (i, item) {
                            $("#YCSH").text(item.PA_Sun)
                            SH = $("#YCSH").text()
                        })
                    }
                })
                //点击切换纸板类型，来搜索克重信息
                $(document).on("change", ".JS_HZLX", function (e) {
                    var ZLX = $(e.target).val();
                    $.ajax({
                        url: '/Procure/Pricing',
                        type: 'GET',
                        data: { "ZLX": ZLX, "state": 3 },
                        success: function (data) {
                            createKEZ(data);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    //打印克重信息下拉列表
                    function createKEZ(date) {
                        $(e.target).parent().next().children().first().children().first().next().remove()
                        $.each(date, function (i, item) {
                            var $tr = $(`<option value="${item.PA_Pke}" id="CL_ID">${item.PA_Pke}</option>`);
                            $(e.target).parent().next().children().first().append($tr);
                        })
                    }
                })
                //点击切换瓦楞系数
                $(document).on("change", ".JS_LB", function (e) {
                    var ZLB = $("#JS_LB1").val() + $("#JS_LB2").val()
                    var WLXS = $(e.target).val();
                    $("#JS_ZLB").text(ZLB)
                    $.ajax({
                        url: '/Procure/Pricing',
                        type: 'GET',
                        data: { "WLXS": WLXS, "state": 4 },
                        success: function (data) {
                            createLXKZ(data);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    //打印瓦楞的系数信息
                    function createLXKZ(date) {
                        $(e.target).parent().next().children().first().children().first().next().remove()
                        $.each(date, function (i, item) {
                            var $tr = $(`<option value="${item.PA_Xishu}" id="CL_ID">${item.PA_Xishu}</option>`);
                            $(e.target).parent().next().children().first().append($tr);
                        })
                    }
                    $.ajax({
                        url: '/Procure/Pricing',
                        type: 'GET',
                        data: { "ZLX": ZLB, "state": 7 },
                        success: function (data) {
                            JS_JGF(data)
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    function JS_JGF(data) {
                        $("#JGF").text("")
                        $.each(data, function (x, obj) {
                            $("#JGF").text(obj.PA_Jia)
                        })
                    }
                })
                //计算面纸/中纸/底纸平方价格
                $(document).on("change", ".JS_ZDJ", function (e) {
                    alert(22)
                    var ycfz = null
                    var MK = $(e.target).val();
                    var ML = $(e.target).parent().prev().children().first().val();
                    var Zancun = $(e.target).next().text()
                    var PFJG = $("#CHJG").text()
                    $.ajax({
                        url: "/Procure/Pricing",
                        type: 'GET',
                        data: { "MK": MK, "ML": ML, "state": 5 },
                        success: function (data) {
                            JSJG(data)
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    function JSJG(date) {
                        $.each(date, function (i, item) {
                            $("#YCFZ").text(item.PA_price)
                            ycfz = $("#YCFZ").text()
                        })
                        var jg = (ycfz * 0.000001 * MK)
                        $(e.target).next().text(jg)
                        var b = $("#Z1").text() * 1 + $("#Z2").text() * 1 + $("#Z3").text() * 1 + $("#Z4").text() * 1 + $("#Z5").text() * 1
                        var a = b * SH

                        $("#CHJG").text(b)
                        $("#PFJG").text(a + b)
                    }

                })
                //计算瓦楞平方价格
                $(document).on("change", ".JS_WLKZ", function (e) {
                    var ycfz = null
                    var MK = $(e.target).val();//平方克重
                    var ML = $(e.target).parent().parent().prev().children().first().val();//瓦楞系数
                    var MB = $(e.target).parent().parent().prev().prev().children().first().val();//瓦楞系数
                    var PFJG = $("#CHJG").text()
                    $.ajax({
                        url: "/Procure/Pricing",
                        type: 'GET',
                        data: { "MB": MB, "ML": ML, "state": 6 },
                        success: function (data) {
                            JSJG(data)
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    function JSJG(date) {
                        $.each(date, function (i, item) {
                            $("#YCFZ").text(item.PA_price)
                            ycfz = $("#YCFZ").text()
                        })
                        var jg = (ycfz * 0.000001 * MK)
                        $(e.target).parent().next().text(jg)
                        var b = $("#Z1").text() * 1 + $("#Z2").text() * 1 + $("#Z3").text() * 1 + $("#Z4").text() * 1 + $("#Z5").text() * 1
                        var a = b * SH

                        $("#CHJG").text(b)
                        $("#PFJG").text(a + b)
                    }
                })
                //提交核算的理论成本
                $(document).on("click", "#CBJSTJ", function (e) {
                    var jgf = $("#JGF").text() * 1
                    var pfjg = $("#PFJG").text() * 1
                    console.log(jgf)
                    var xx = jgf + pfjg
                    if (jgf != "") {
                        if (pfjg != "") {
                            $(x.target).next().text(xx)
                        }
                        else {
                            alert("纸板价格为空，请选择纸板")
                        }
                    }
                    else {
                        alert("加工费为空，请选择楞型")
                    }
                    $("#HJ_SF").css({ "display": "none" });
                })
             
            })
            //点击展开BOM，查看当前BOM下的采购询价信息 
            $(document).on("click", "#HJ_ZKXX", function (e) {
                if ($(e.target).next().next().css("display") == "none") {
                    $(e.target).next().next().css({ "display": "block" });
                }
                else {
                    $(e.target).next().next().css({ "display": "none" });
                }
                var LH = $(e.target).next().children().first().next().next().children().last().text()
                var App_bian = $("#HJ_SQDH").text()
                $.ajax({
                    url: '/Procure/Pricing',
                    type: 'GET',
                    data: { "LH": LH, "APP_bian": App_bian, "state": 2 },
                    success: function (data) {
                        createINF(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
                function createINF(data) {
                    $(e.target).next().next().children().first().children().last().children().remove();
                    $.each(data, function (i, item) {
                        var $tr = $(`
                                    <tr>
                                        <th scope="col"><input type="radio"name="${item.Inf_wu}"/></th>
                                        <th scope="col" style="display:none">${item.Inf_id}</th>
                                        <th scope="col" id="BZ_gys">${item.Inf_gong}</th>
                                        <th scope="col"id="BZ_hj">${item.Inf_huiP}</th>
                                        <th scope="col" id="BZ_wu" >${item.Inf_wu}</th>
                                        <th scope="col"id="BZ_liao" >${item.Inf_liao}</th>
                                    </tr>
                            `);
                        $(e.target).next().next().children().first().children().last().append($tr);
                    })
                }
            })
            //点击修改订单步骤,完成原材料核价
            $(document).on("click", "#HJ_WCHJ", function () {
                var app_buy = {
                    Ap_bian: $("#HJ_SQDH").text(),
                    App_bu:"6"
                }
                $.ajax({
                    url: "/Procure/Modify_App_bu",
                    type: "POST",
                    data: app_buy,
                    success: function (data) {
                        if (data == "修改成功") {
                            alert(data);
                            $(location).attr('href', '/Procure/Overview')
                        }
                            
                    },
                    error: function (data) {
                        alert("erroer ");
                    },
                })
            })
            //返回查看申请单页面
            $(document).on("click", "#HJ_FH", function () {
                $(location).attr('href', '/Procure/Overview')
            })
        })
    </script>


}